<!DOCTYPE html>
<html lang="zh-CN">
  <head>
        <#include "/common/common_head.ftl">
        <script>
            function  changeFileType(e) {
                if(e.selectedIndex == 0){
                    $("#patchContent").hide();
                }else{
                    $("#patchContent").show();
                }
            }
            
            function addForm() {
                var appKey = $("#appKey").val();
                if(appKey == ""){
                    alert("应用标识不能为空!");
                    return;
                }
                var uploadFile = $("#uploadFile").val();
                if(uploadFile == ""){
                    alert("上传文件不能为空!");
                    return;
                }
                var versionCode = $("#versionCode").val();
                if(versionCode == ""){
                    alert("版本号不能为空!");
                    return;
                }
                var fileType = $("#fileType").val();
                if(fileType == 1){
                	var versionName = $("#versionName").val();
	                if(versionName == ""){
	                    alert("版本名不能为空!");
	                    return;
	                }
                }
                if(fileType == 2){
                    var patchCode = $("#patchCode").val();
                    if(patchCode == ""){
                        alert("补丁号不能为空!");
                        return;
                    }
                    var patchName = $("#patchName").val();
                    if(patchName == ""){
                        alert("补丁名不能为空!");
                        return;
                    }
                }
                $.ajax({
					type : "get",//使用get方法访问后台
					url : "getCode.do",//要访问的后台地址
					data:"appKey=" + appKey + "&fileType=" + fileType + "&versionCode=" + versionCode,
					async:false,
					success:function(data) {//msg为返回的数据，在这里做数据绑定 
						var code = data;  
					    if(fileType == 1){
					    	if(versionCode <= code){
					    		alert("此应用标识版本号过低或者已经存在,请递增填写");
					    		return;
					    	}
					    	$("#addForm").submit();
					    }else{
					    	var patchCode = $("#patchCode").val();
					    	if(patchCode <= code){
					    		alert("此应用标识补丁号过低或者已经存在,请递增填写");
					    		return;
					    	}
					    	$("#addForm").submit();
					    }
					},
					error:function() {
						alert("抱歉，查询失败 ，请您重试。");
						return false;
					}
				});
            }
        </script>
  </head>
  <style>
  	.formbtn {
  	  text-align:center;
  	}
  </style>
  <body style="padding-top:0px">
        <!-- 主内容区域 S -->
 		<div class="" id="mainBoard">
        <#if version??>
            <#assign operate="编辑">
        <#else>
            <#assign operate="添加">
        </#if>
		<!-- 导航路径 S -->
		<ol class="breadcrumb">
		  <li><a href="#">版本管理</a></li>
		  <li class="active">${operate}版本信息</li>
		  <li><a href="list.do?page=${page}">返回</a></li>
		</ol>
		<!-- 导航路径 E -->

		<!-- 标题区 S -->
		<h2 class="sub-header">${operate}版本信息</h2>
		<!-- 标题区 E -->

		<!-- 内容区 S -->
        <#if version??>
		<form action="update.do" method="post" enctype="multipart/form-data">
		    <input type="hidden" name="id"         value="${version.id?string('###')}">
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">应用名称</span>
                <div class="form-control">${version.appName?if_exists}</div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">应用标识</span>
                <div class="form-control">${version.appKey?if_exists}</div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">文件类型</span>
               <div class="form-control">
                    <#if version.fileType == 1>版本</#if>
                    <#if version.fileType == 2>补丁</#if>
               </div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">文件路径</span>
                <div class="form-control">${version.fileUrl?if_exists}</div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">版本编号</span>
                <div class="form-control">${version.versionCode?if_exists}</div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">版本名称</span>
                <div class="form-control">${version.versionName?if_exists}</div>
            </div>
             <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">补丁编号</span>
                <div class="form-control">${version.patchCode?if_exists}</div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">补丁名称</span>
                <div class="form-control">${version.patchName?if_exists}</div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">强制更新</span>
                <div class="form-control">
                	<#if version.enforce == 1>是</#if>
                    <#if version.enforce == 0>否</#if>
                </div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">描述信息</span>
                <div class="form-control">
                	${version.remark}
                </div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">更新日志</span>
                <textarea  rows="3" cols="20" class="form-control" placeholder="changeLog" aria-describedby="basic-addon5" name="changeLog">${version.changeLog?if_exists}</textarea>
            </div>
            <div class="formbtn"><button type="submit" class="btn-primary">提交</button></div>
		</form>
        <#else>
		<form id="addForm" action="save.do" method="post" enctype="multipart/form-data">
            <div class="input-group">
              <span class="input-group-addon" id="basic-addon2">应用名称</span>
              <input class="form-control" id="appName" placeholder="appName" aria-describedby="basic-addon5" name="appName">
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">应用标识</span>
                <input class="form-control" data-bv-notempty="true"
                       data-bv-notempty-message="应用标识不能为空" placeholder="appKey" aria-describedby="basic-addon5" id="appKey" name="appKey">
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">文件类型</span>
                <select class="form-control" name="fileType" id="fileType" onchange="changeFileType(this)">
                    <option value="1">版本</option>
                    <option value="2">补丁</option>
                </select>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">文件上传</span>
                <input type="file" data-bv-notempty="true"
                       data-bv-notempty-message="上传文件不能为空" class="form-control" placeholder="uploadfile"  id="uploadFile" aria-describedby="basic-addon2" name="file">
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">版本编号</span>
                <input class="form-control"  data-bv-notempty="true" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')"
                       data-bv-notempty-message="版本编号不能为空" placeholder="versionCode" aria-describedby="basic-addon5" id="versionCode" name="versionCode">
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">版本名称</span>
                <input class="form-control" placeholder="versionName" aria-describedby="basic-addon5" id="versionName" name="versionName">
            </div>
            <div id="patchContent" style="display: none">
                <div class="input-group">
                    <span class="input-group-addon" id="basic-addon2">补丁编号</span>
                    <input class="form-control" data-bv-notempty="true" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')"
                           data-bv-notempty-message="补丁编号不能为空" placeholder="patchCode" aria-describedby="basic-addon5" id="patchCode" name="patchCode">
                </div>

                <div class="input-group">
                    <span class="input-group-addon" id="basic-addon2">补丁名称</span>
                    <input class="form-control" placeholder="patchName" aria-describedby="basic-addon5" id="patchName" name="patchName">
                </div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">更新日志</span>
                <textarea rows="3" cols="20" class="form-control" placeholder="changeLog" aria-describedby="basic-addon5" name="changeLog"></textarea>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">强制更新</span>
                <select class="form-control" name="enforce" id="enforce">
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon2">描述信息</span>
                <input class="form-control" placeholder="remark" aria-describedby="basic-addon5" name="remark">
            </div>
            <div class="formbtn"><button type="button" class="btn-primary" onclick="addForm()">提交</button></div>
		</form>
        </#if>
		<!-- 内容区 E -->
 		<!-- 主内容区域 E -->
		
 	</div>
  </body>
</html>
